/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Golf_Manager.sqlite.sql;

import Golf_Manager.vo.JoinMember;

/**
 *
 * @author Administrator
 */
public class JoinMemberSql {
    
    public static StringBuffer getJoinMembersSql(String selectKey, String orderString) {
        
        StringBuffer joinMemberSql = new StringBuffer();
        
        joinMemberSql.append("SELECT");
        joinMemberSql.append(" MEMBER_SEQ, ");
        joinMemberSql.append(" NAME, ");
        
        if(selectKey != null && !selectKey.equals("")){
            joinMemberSql.append(" BIRTH, ");
            joinMemberSql.append(" ").append(selectKey).append(" ");
        } else {
            joinMemberSql.append(" BIRTH ");
        }
        joinMemberSql.append("FROM MEMBER ");
        joinMemberSql.append("WHERE JOINYN = '참여' ");
        
        if(orderString != null && !orderString.equals("")){
            joinMemberSql.append("ORDER BY ").append(orderString);
        } else {
            joinMemberSql.append("ORDER BY NAME ");
        }
        
        //System.out.println(joinMemberSql.toString());
        
        return joinMemberSql;
    }
    
    public static StringBuffer getInsertJoinMemberSql(String groupDate, JoinMember joinMember) {
        
        StringBuffer insertjoinMemberSql = new StringBuffer();
        
        insertjoinMemberSql.append("INSERT INTO JOINMEMBERS (GDATE,  GROW,  GCOL,  GNAME, MSEQ, MNAME, MBIRTH, MSCORE) ");
        insertjoinMemberSql.append("VALUES ( '" ).append(groupDate).append("', ");
        insertjoinMemberSql.append("'").append(joinMember.getGroupRow()).append("', ");
        insertjoinMemberSql.append("'").append(joinMember.getGroupCol()).append("', ");
        insertjoinMemberSql.append("'").append(joinMember.getGroupNm()).append("', ");
        insertjoinMemberSql.append("'").append(joinMember.getMemberSeq()).append("', ");
        insertjoinMemberSql.append("'").append(joinMember.getName()).append("', ");
        insertjoinMemberSql.append("'").append(joinMember.getBirth()).append("', ");
        insertjoinMemberSql.append("'").append(joinMember.getScore() == null ? "" : joinMember.getScore()).append("')");
        
        //System.out.println(insertjoinMemberSql.toString());
        
        return insertjoinMemberSql;
    }
    
    public static StringBuffer getDeleteJoinMemberSql(String groupDate) {
        
        StringBuffer deleteJoinMemberSql = new StringBuffer();
        
        deleteJoinMemberSql.append("DELETE FROM JOINMEMBERS ");
        deleteJoinMemberSql.append("WHERE GDATE IN ('" ).append(groupDate).append("')");
        
        //System.out.println(deleteJoinMemberSql.toString());
        
        return deleteJoinMemberSql;
    }
}
